import 'package:flutter/material.dart';

import 'AnimationImage.dart';

/// @date 2020/08/06  17:11
/// @author 程志强
/// @des 基础缩放动画

class AnimationScaleRoute2 extends StatefulWidget {
  @override
  _AnimationScaleRoute2State createState() => _AnimationScaleRoute2State();
}

class _AnimationScaleRoute2State extends State<AnimationScaleRoute2>
    with SingleTickerProviderStateMixin {
  Animation<double> _animation;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller =
        AnimationController(duration: const Duration(seconds: 3), vsync: this);
    // 使用弹性曲线
    _animation = CurvedAnimation(parent: _controller, curve: Curves.bounceIn);
    // 图片宽高从0变到300
    _animation = Tween(begin: 0.0, end: 300.0).animate(_controller)
      ..addListener(() {
        setState(() {});
      });
    // 启动动画
    _controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("基础动画2"),
      ),
      body: AnimationImage(
        imgPath: "https://inews.gtimg.com/newsapp_bt/0/10735498766/1000",
        animation: _animation,
      ),
    );
  }

  @override
  void dispose() {
    // 路由销毁时释放动画资源
    _controller.dispose();
    super.dispose();
  }
}
